#include <iostream>
#include <thread>
#include <future>
#include <chrono>

int Sub(int num1, int num2)
{
    std::cout << "减法开始操作" << std::endl;
    return num1 - num2;
}

int main()
{
    std::cout << "------1------" << std::endl;
    //在对象调用get获取异步结果时，才执行异步任务
    // std::future<int> future = std::async(std::launch::deferred, Sub, 20, 10);
    //async:内部创建线程异步帮我们完成任务
    std::future<int> future = std::async(std::launch::async, Sub, 20, 10);

    std::this_thread::sleep_for(std::chrono::seconds(1));
    std::cout << "------2------" << std::endl;
    std::cout << future.get() << std::endl;
    std::cout << "------3------" << std::endl;
    return 0;
}